<?php
if(checarUsuario(0)){
	?>
<script
	type="text/javascript" src="../js/postagens.js"></script>
<div class="row">
	<div class="col-lg-12">
		<h3 class="page-header">
			<b>Minhas Noticias</b>
		</h3>
	</div>
</div>
<div class="row">
	<div class="col-lg-12">
		<form action="index.php?pag=postagens" method="POST">
			<div class="panel panel-primary">
				<div class="panel-heading">Busca</div>
				<div class="panel-body">
					<div class="row">
						<div class="col-lg-6">
							<label class="label-control">Data Inicio</label> <input
								type="date" name="dtInicio" id="dtInicio" />
						</div>
						<div class="col-lg-6">
							<label class="label-control">Data Final</label> <input
								type="date" name="dtFinal" id="dtFinal" />
						</div>
					</div>
					<div class="row">
						<div class="col-lg-6">
							<button class="btn btn-primary btn-sm" type="submit">
								<span class="glyphicon glyphicon-search"></span> Buscar
							</button>
						</div>
					</div>
				</div>
			</div>
		</form>
	</div>
</div>
<div class="row">
	<div class="col-lg-12">
		<table class="table">
			<thead>
				<tr>
					<th>Titulo</th>
					<th>Data</th>
					<th>Hora</th>
					<th>Ação</th>
				</tr>
			</thead>
			<tbody>
			<?php
			$where = '';
			if(isset($_POST['dtInicio'])){
				$dataInicio = str_replace('/','.',$_POST['dtInicio']);
				$dataFinal = str_replace('/','.',$_POST['dtFinal']);
				$where = " and data between '$dataInicio' and '$dataFinal' ";
			}
			$query = "select * from postagem where usuario = '".$_SESSION['user']."'$where order by data desc, hora desc";
			$sql_news = $conn->query($query);
			while ($news = $sql_news->fetch(PDO::FETCH_OBJ)){?>
				<tr>
					<td><?php echo $news->titulo; ?></td>
					<td><?php echo dataBancoByPt($news->data); ?></td>
					<td><?php echo dataBancoByPt($news->hora); ?></td>
					<td><?php echo $news->estado == 'P' ? '<button id="postar" codigo="'.$news->codigo.'" class="btn btn-primary btn-xs" title="Submeter"><span class="glyphicon glyphicon-check"></span></button>' : ''; ?>
						<a class="btn btn-default btn-xs" title="Editar"
						href="index.php?pag=postagem/altera&cod=<?php echo $news->codigo?>"><span
							class="glyphicon glyphicon-pencil"></span> </a> <a
						class="btn btn-danger btn-xs" title="Excluir"
						href="model/postagem_remove.php"><span
							class="glyphicon glyphicon-remove"></span> </a>
						<button class="btn btn-info btn-xs" title="Visualizar"
							onclick="mostrarPostAdm(<?php echo $news->codigo?>)">
							<span class="glyphicon glyphicon-file"></span>
						</button>
					</td>
				</tr>
				<?php } ?>
			</tbody>
		</table>
	</div>
</div>
<div id="dialog" class="modal fade"
	data-backdrop="static">
	<div class="modal-dialog">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal">
					<span aria-hidden="true">&times;</span><span class="sr-only">Close</span>
				</button>
				<h4>Postagem</h4>
			</div>
			<div class="modal-body"></div>
			<div class="modal-footer">
				<button type="button" class="btn btn-default" data-dismiss="modal">Fechar</button>
			</div>
			<!-- /.modal-content -->
		</div>
		<!-- /.modal-dialog -->
	</div>
	<!-- /.modal -->
</div>
				<?php }else{
					$_SESSION['msg_erro'] = "Usuário não autorizado, contate o administrador.";
					echo '<script>window.location="../index.php"</script>';
				}?>